package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.Comments;
import com.ruoyi.system.domain.Posts;
import com.ruoyi.system.mapper.CommentsMapper;
import com.ruoyi.system.mapper.PostsMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ReportMapper;
import com.ruoyi.system.domain.Report;
import com.ruoyi.system.service.IReportService;

/**
 * 用户举报记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@Service
public class ReportServiceImpl implements IReportService 
{
    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private PostsMapper postsMapper;

    @Autowired
    private CommentsMapper commentsMapper;

    /**
     * 查询用户举报记录
     * 
     * @param reportId 用户举报记录主键
     * @return 用户举报记录
     */
    @Override
    public Report selectReportByReportId(Long reportId)
    {
        return reportMapper.selectReportByReportId(reportId);
    }

    /**
     * 查询用户举报记录列表
     * 
     * @param report 用户举报记录
     * @return 用户举报记录
     */
    @Override
    public List<Report> selectReportList(Report report)
    {
        List<Report> reports = reportMapper.selectReportList(report);
        for (Report report1 : reports) {
            SysUser sysUser = sysUserMapper.selectUserById(report1.getUserId());
            report1.setUserName(sysUser.getUserName());
            Posts posts = postsMapper.selectPostsByPostId(report1.getPostId());
            report1.setPostName(posts.getTitle());
            Comments comments = commentsMapper.selectCommentsByCommentId(report1.getCommentId());
            report1.setCommentName(comments.getContext());

        }
        return reports;
    }

    /**
     * 新增用户举报记录
     * 
     * @param report 用户举报记录
     * @return 结果
     */
    @Override
    public int insertReport(Report report)
    {
        return reportMapper.insertReport(report);
    }

    /**
     * 修改用户举报记录
     * 
     * @param report 用户举报记录
     * @return 结果
     */
    @Override
    public int updateReport(Report report)
    {
        return reportMapper.updateReport(report);
    }

    /**
     * 批量删除用户举报记录
     * 
     * @param reportIds 需要删除的用户举报记录主键
     * @return 结果
     */
    @Override
    public int deleteReportByReportIds(Long[] reportIds)
    {
        return reportMapper.deleteReportByReportIds(reportIds);
    }

    /**
     * 删除用户举报记录信息
     * 
     * @param reportId 用户举报记录主键
     * @return 结果
     */
    @Override
    public int deleteReportByReportId(Long reportId)
    {
        return reportMapper.deleteReportByReportId(reportId);
    }
}
